<?php $this->load->view("header");?>
<div id="search-project">
    <?php $this->load->view('sideBlocks/searchBlock') ?>
</div>
<?php
    if(isset($projectDetail) == TRUE) {
        $projectDetail = $projectDetail->row();
    }
?>
<div class="wrap-content-app wrap-project wrap-detail-project">
<div class="container no-padding">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 detail-project-after-create no-padding">
            <div class="border col-md-1"></div>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 f24-m title-project-after-create-success">
                <?php echo $this->lang->line('Success! your job was submitted');?>
            </div>
            <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9 f18-m no-padding">
                <?php echo $this->lang->line('The top 10 recommended freelancers');?> - <span id="name-project"> ( <?php if($projectDetail->project_name) echo $projectDetail->project_name;?> )</span>
<!--                <input type="text" class="form-control" id="title-project" value="--><?php //if($projectDetail->project_name) echo $projectDetail->project_name;?><!--" />-->
            </div>
            <div class="col-lg-offset-1 col-lg-1 col-md-3 col-sm-3 col-xs-3">
                <button type="button" style="display: none;" class="btn-cancel-choose-invite btn btn-primary"><?php echo $this->lang->line('Cancel')?></button>
                <button id="btn-invite-all" type="button" class="btn btn-primary bg-green"><?php echo $this->lang->line('Invite all to apply')?></button>
                <div class="col-lg-12" id="invite-alert"></div>
            </div>
            <?php
                if((isset($userCate) == TRUE) && (count($userCate) > 0)){ $dem = 0;
                    ?>
                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 list-dev-recommended no-padding">
                        <?php
                        foreach($userCate as $item){ $dem++;
                            if(!empty($UserInvited)) {
                                if (in_array($item->id, $UserInvited)) {
                                    $Invited = "Invited";
                                }else{
                                    $Invited = "";
                                }
                            }else {
                                    $Invited = "";
                                }

                        ?>
                    <div data-id="<?php echo $item->id?>" data-placement='above' class="col-lg-3 col-md-3 col-sm-3 col-xs-12 item-dev-recommend <?php if($Invited) echo $Invited?>">
                                <div class="col-lg-5 col-md-4 col-sm-4 col-xs-12 no-padding"><img class="img-responsive" src="<?php
                                    if ( (is_file_exists($item->logo) == TRUE ) && ($item->logo != "")) echo uimage_url($item->logo); else echo image_default();
                                    ?>" /></div>
                                <div class="col-lg-7 col-md-8 col-sm-8 col-xs-12 no-padding-right">
                                    <span><?php echo $item->user_name;?></span>
                                    <span><input value="<?php echo $item->user_rating?>" type="number" data-star-captions="{}" data-default-caption="{rating}" class="rating" min=0 max=5  data-size="xs" disabled></span>
                                    <button type="button" data-href="<?php echo site_url("userList/inviteOneProgrammer/".$item->id."/".$projectDetail->id)?>" id="btn-invite-one"  class="btn btn-primary btn-invite"><?php echo $this->lang->line('Invite')?></button>
                                </div>
                                <div id="popover_info_dev_1" data-toggle="popover_info_dev" style="display: none" class="col-lg-12">
                                    <div class="col-lg-4">

                                    </div>
                                    <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
                                        <div><?php //echo getCountry($single_user['country_id'])->row()->country_name;
                                            $result = getCountry($item->country_id);
                                            if($result->num_rows() > 0)
                                                echo $result->row()->country_name;
                                            ?></div>

                                        <div><?php echo $item->num_reviews?> reviews</div>
                                        <div>2 jobs</div>
                                        <div>Levels 5</div>
                                        <div>Tỷ lệ hoàn thành 100%</div>
                                    </div>
                                </div>
                            </div> <!--            item-dev-recommend-->
                <?php if($dem % 4 == 0) echo "<div class='clear'></div>"; } ?>

                </div>
                <div class="list-load-more col-lg-12 col-md-12 col-xs-12 col-sm-12"></div>
                <div class="col-lg-offset-10 col-lg-2" style="text-align: right;">
                    <a id="link-more">more >> </a>
                </div>
            <?php } ?>
                <div class="col-md-12 pr_name f24-m"><?php if($projectDetail->project_name) echo $projectDetail->project_name;?></div>
                <?php
                if($projectDetail->project_status ==0){
                    $status = "Open";
                    $class = "green-2";
                    $icon = "glyphicon-remove";
                    $value = "Close";
                }else{
                    $status = "Close";
                    $class = "red";
                    $value = "Open";
                    $icon = "glyphicon-ok";
                }
                ?>
                <div class="col-md-12 pr_option">
                    <div class="col-md-3 pr_option_item"><span class="glyphicon glyphicon-edit"> <a class="grey-1 f18-m" href="<?php echo site_url('project/editProject/'.$projectDetail->id)?>">Edit</a></span></div>
                    <div class="col-md-3 pr_option_item"><span id="icon-status" class="glyphicon <?php echo $icon;?> fix-glyphicon"> <a style="cursor:pointer" data-toggle="confirmation-change-status" class="grey-1 f18-m" data-toggle="confirmation" data-btn-ok-label="Continue" data-btn-ok-icon="glyphicon glyphicon-share-alt" data-btn-ok-class="btn-success" data-btn-cancel-label="Stoooop!" data-btn-cancel-icon="glyphicon glyphicon-ban-circle" data-btn-cancel-class="btn-danger" id="btn-status-project"><?php echo ($value) ? $value : "";?>
                            </a></span></div>
                    <div class="col-md-6 pr_option_item">

                        <span class="col-md-4 glyphicon glyphicon-fullscreen">
                            <a id="a-extend" class="grey-1 f18-m"><?php echo $this->lang->line('Extend');?></a>
                        </span>
                        <div class="col-md-5">
                            <input type="number" id="txt-extend" class="form-control" />
                        </div>
                        <div class="col-md-3">
                            <button id="btn-extend" type="button" class="btn btn-success"><?php echo $this->lang->line('Extend');?></button>
                        </div>
                        <div class="col-md-offset-5 col-md-7 col-xs-12 col-sm-12 alert" id="extend-alert"></div>
                    </div>
                </div>
                <div class="col-md-12 pr_info">
                    <div class="col-md-2">
                        <div class="pr_info_title f18-m text-center">Đang bid</div>
                        <div class="pr_info_content text-center"><?php echo getNumBid($projectDetail->id)?></div>
                    </div>
                    <div class="col-md-2 text-center">
                        <div class="pr_info_title f18-m">Giá trung bình</div>
                        <div class="green f30-m green-2 font-bold"><?php  echo getBidsInfo($projectDetail->id)?></div>
                    </div>
                    <div class="col-md-4">
                        <div class="pr_info_title f18-m text-center">Ngân sách</div>
                        <div class="f30-m font-bold text-center yellow-2"><?php if ($projectDetail->budget_min != '0') echo '$ ' . $projectDetail->budget_min; else echo 'N/A'; ?> - <?php if ($projectDetail->budget_max != '0') echo '$ ' . $projectDetail->budget_max; else echo 'N/A'; ?></div>
                    </div>
                    <div class="col-md-2">
                        <div class="pr_info_title f18-m text-center">Hạn chót bid</div>
                        <div id="days-extends" class="pr_info_content text-center"><?php echo days_left($projectDetail->enddate,$projectDetail->id)?></div>
                    </div>
                    <div class="col-md-2">
                        <div class="pr_info_title f18-m text-center">Status</div>
                        <div id="status-project" data-id="<?php echo $projectDetail->project_status;?>" class="pr_info_content text-center <?php echo ($class) ? $class : "";?>"><?php echo ($status) ? $status : "" ;?></div>
                    </div>
                </div>
                <div class="col-md-12 bg-fe no-padding">
                    <div class="col-md-8">
                        <div class="divide f16-m">
                            <div class="pr_title pr_name f24-m">Project detail</div>
                            <div id="desc-project" class="pr_content"><?php echo $projectDetail->description;?> </div>

                        </div>
                        <div class="divide f14-m">
                            <div class="pr_title f24-m">Skill</div>
                            <div id="pr_name_skill" class="pr_name_skill"><?php echo getCategoryLinks($projectDetail->project_categories)?></div>
                        </div>
                    </div>
                    <div class="col-md-4 bg-pink about-employer">
                        <div class="about_employer text-center f24-m">About the Employer</div>
                        <div class="rating-freelancer no-padding text-center">
                            <input  value="<?php echo $projectDetail->user_rating;?>" type="number" data-star-captions="{}" data-default-caption="{rating}" class="rating" min=0 max=5  data-size="xs" disabled="disabled">
                        </div> <!-- rating-freelancer -->
                        <div class="col-lg-12 text-center f18-m">
                            <div class="col-lg-12"><span>Total spent</span> $100</div>
                            <div class="col-lg-12"><?php echo $projectDetail->num_reviews;?> reviews</div>
                            <div class="col-lg-12"><?php echo getNumProjectByUser($projectDetail->creator_id)?> open jobs</div>
                            <div class="col-lg-12">Payment Method Not Verified</div>
                            <div class="col-lg-12">Project ID : 6529791</div>
                        </div>

                    </div>
                </div>


    </div>
    </div>
<div class="wrap-content wrap-public-message">
	<div class="row-bids">
		<div class="container">
			<div class="row">
				<!-- Place show tab -->
				<div class="col-md-2 col-lg-2 col-sm-2 col-xs-2 no-padding">
					<ul class="nav nav-pills nav-justified nav-bids" role="tablist">
				        <li class="active"><a href="#all" role="tab" data-toggle="tab">All</a></li>
				        <li><a href="#shortlist" role="tab" data-toggle="tab">Shortlist</a></li>
				    </ul>		    
				</div><!-- end place show tab-->
				<!-- sort by-->
				<div class="col-md-5 col-lg-5 col-sm-5 col-xs-5 no-padding" style="float:right">
					<div class="col-md-4 col-lg-4 col-sm-4 col-xs-4" style="top:12px;text-align:right">Sort By</div>
					<div class="col-md-8 col-lg-8 col-sm-8 col-xs-8">
						<form id="frm-sort-bids" action="" method="GET">
							<select class="select-sort selectpicker" name="sort">
							  	<option value="tot_rating" data-dir="desc" <?php echo (isset($sort) && $sort == 'tot_rating' && isset($dir) && $dir == 'desc')?"selected":''?>><?php echo $this->lang->line('Rating: hight to low')?></option>
							  	<option value="tot_rating" data-dir="asc" <?php echo (isset($sort) && $sort == 'tot_rating' && isset($dir) && $dir == 'asc')?"selected":''?>><?php echo $this->lang->line('Rating: low to hight')?></option>
							  	<option value="num_reviews" data-dir="desc" <?php echo (isset($sort) && $sort == 'num_reviews' && isset($dir) && $dir == 'desc')?"selected":''?>><?php echo $this->lang->line('Feedback: hight to low')?></option>
							  	<option value="num_reviews" data-dir="asc" <?php echo (isset($sort) && $sort == 'num_reviews' && isset($dir) && $dir == 'asc')?"selected":''?>><?php echo $this->lang->line('Feedback: low to hight')?></option>
							  	<option value="country_name" data-dir="desc" <?php echo (isset($sort) && $sort == 'country_id' && isset($dir) && $dir == 'desc')?"selected":''?>><?php echo $this->lang->line('Location: hight to low')?></option>
							  	<option value="country_name" data-dir="asc" <?php echo (isset($sort) && $sort == 'country_id' && isset($dir) && $dir == 'asc')?"selected":''?>><?php echo $this->lang->line('Location: low to hight')?></option>
							</select>
							<input type="hidden" name="dir" id="dir" value="">
						</form>
					</div>
				</div><!--end sort by-->
			</div>
		</div>
	</div>
</div>
<div class="container container-bids" style="font-family: 'UTM-Hel'">	
	<div class="row">
		<div style="margin-top: 0px;" class="col-md-12 col-lg-12 col-sm-12 col-xs-12 no-padding">
			<div class="col-md-12 col-lg-12 col-sm-12 col-xs-12 title_put_bids no-padding" >
				<div class="col-md-10 col-lg-10 col-sm-10 col-xs-10 title_put_bids_name">Đang đặt giá (<?php echo $numbids;?>)</div>
				<div class="col-md-2 col-lg-2 col-sm-2 col-xs-2 title_put_bids_name" style="padding-left:12px">Đặt giá</div>
			</div>
	
			<div class="col-md-12 col-lg-12 col-sm-12 col-xs-12 tab-content">
				<!-- all tab-->
		    	<div class="tab-pane active fade in" id="all">
		    		
		    		<?php $this->load->view("project/show_all_tab"); ?>
		    		
		    	</div><!--end all tab-->
		    	<!-- shortlist tab -->
		    	<div class="tab-pane fade in" id="shortlist">
		    		<?php
		    			//$arrayUser = $this->session->userdata("project_".$project_id);
		    			$this->load->view("project/show_shortlist_tab");
		    		?>
		    	</div><!-- end shortlist tab -->
		    </div>
		</div>
	</div>
</div>
</div>

<script>
        $(document).ready(function(){
            $(".item-dev-recommend").each(function(){
                if($(this).hasClass('Invited')){
                    //$(this).addClass('item-dev-recommend-opacity');
                    $(this).css('cursor','no-drop');
                    $(this).off('click');
                    $(this).find('.btn-invite').text('Invited');
                    $(this).find('.btn-invite').prop('disabled',true);
                    $(this).append('<span class="glyphicon glyphicon-ok green-2"></span>');
                }else{
                    $(this).find('.btn-invite').prop('disabled',false);
                }
            });
        });
        $("#btn-invite-all").on('click',function(){
            var array = [];
            $(".item-dev-recommend-opacity").each(function(){
                array.push($(this).attr('data-id'));
            });
            <?php
                if($this->loggedInUser->id != $projectDetail->creator_id){
            ?>
                alert('You must post this project to invite');
                return false;
            <?php } ?>

            if(array.length === 0){
                $(".item-dev-recommend:not(.Invited)").each(function(){
                    array.push($(this).attr('data-id'));
                });
                if(array.length == 0)
                    return false;
                $.ajax({
                    type:"POST",
                    url : BASE_URL+"/index.php/userList/inviteAll",
                    data: "array="+array+"&project_id="+<?php echo $projectDetail->id;?>,
                    success:function(data){
                        var data = $.parseJSON(data);
                        if(data.status = 'success'){
                            $('.alert-invite').modal('show');
                            //window.location.reload();
                            BootstrapDialog.show({
                                title: 'Applancer',
                                message: '<?php echo $this->lang->line('Invite success')?>'
                            });
                            setTimeout(5000);
                            window.location.reload();
                        }else{
                            $('#invite-alert').text('Mời thất bại');
                        }
                    }
                });
            }else {
                $.ajax({
                    type: "POST",
                    url: BASE_URL + "/index.php/userList/inviteAll",
                    data: "array=" + array + "&project_id=" +<?php echo $projectDetail->id;?>,
                    success: function (data) {
                        var data = $.parseJSON(data);
                        if(data.status = 'success'){
                            //$('.alert-invite').modal('show');
                            //window.location.reload();
                            BootstrapDialog.show({
                                title: 'Applancer',
                                message: '<?php echo $this->lang->line('Invite success')?>'
                            });
                            setTimeout(5000);
                            window.location.reload();
                        }else{
                            $('#invite-alert').text('Mời thất bại');
                        }
                    }
                });
            }
        });
        var num = 0;

        $('body').on('click','.item-dev-recommend',function(){
            if($(this).hasClass('Invited'))
                return false;

            if($(this).hasClass('item-dev-recommend-opacity')){
                num = num - 1;
                if(num != 0)
                    $('#btn-invite-all').text("Invite "+num+" to apply");
                else
                    $('#btn-invite-all').text("Invite all to apply");
                $(this).removeClass("item-dev-recommend-opacity");
                $(this).find('.glyphicon-remove').remove();
            }else{
                $(this).addClass("item-dev-recommend-opacity");
                $(this).append("<span id='remove-choose-invite' class='glyphicon glyphicon-remove'></span>");
                num = num + 1;
                if(num != 0)
                    $('#btn-invite-all').text("Invite "+num+" to apply");
                else
                    $('#btn-invite-all').text("Invite all to apply");
            }

        });


        $('.item-dev-recommend').on('click','.glyphicon-remove',function(e){
            e.preventDefault();
            $(this).remove();
        });

        $('#link-more').on('click',function(){
           var array_list = [];
            $(".item-dev-recommend").each(function(){
                array_list.push($(this).attr('data-id'));
            });
//            $.ajax({
//                type: "POST",
//                url: BASE_URL + "/index.php/users/moreDevRecommened",
//                data: "array=" + array_list,
//                success: function (data) {
//                    var data = $.parseJSON(data);
//                    if(data.status = 'success'){
//                        //window.location.reload();
//                        //console.log(data.data);
//                        $.each(data.data,function(i,item){
//                            $('.list-dev-recommened').append()
//                        });
//                    }else{
//                        //$('#invite-alert').text('Mời thất bại');
//                    }
//                }
//            });
            $.post(BASE_URL+"index.php/users/moreDevRecommened",{'array_list' : array_list,'project_id' : <?php echo $projectDetail->id?>},function(data){
                //console.log(data);
                $('.list-load-more').append(data);
            });
        });


        $('#btn-status-project').on('confirmed.bs.confirmation',function(){
            var status = $("#status-project").attr('data-id');
            if(status == 3) {
                $("#status-project").attr('data-id', '0');
                $("#icon-status").addClass('glyphicon-remove');
                $("#icon-status").removeClass('glyphicon-ok');
                $("#status-project").text('Open');
                $("#btn-status-project").text("Close");
                $("#status-project").addClass('green-2');
                $("#status-project").removeClass('red');
                var stt_update = 0;
            }
            else {
                $("#status-project").attr('data-id', '3');
                $("#icon-status").addClass('glyphicon-ok');
                $("#icon-status").removeClass('glyphicon-remove');
                $("#status-project").text('Close');
                $("#btn-status-project").text("Open");
                $("#status-project").addClass('red');
                $("#status-project").removeClass('green-2');
                var stt_update = 3;
            }
            $.ajax({
                type:"POST",
                url:BASE_URL+"/index.php/project/ajaxCancelProject",
                data: "project_id=<?php echo $projectDetail->id;?>&status="+stt_update,
                success:function(data){
                    var data = $.parseJSON(data);
                    if(data.status == 'success'){
                        if(status == 3)
                            $("#status-project").attr('data-id','0');
                        else
                            $("#status-project").attr('data-id','3');
                    }

                }
            });
        });

        $('#a-extend').clickToggle(function(){
            $("#txt-extend,#btn-extend").show();
        },function(){
            $("#txt-extend,#btn-extend,#extend-alert").hide();

        });
        $("#btn-extend").on('click',function(){
            var time = <?php echo $projectDetail->enddate;?>;
            var day = $("#txt-extend").val();
            if(day == ""){
                $('#extend-alert').text('<?php echo $this->lang->line('Extend numeric');?>');
                return false;
            }
            if (day > 7){
                $('#extend-alert').text('<?php echo $this->lang->line('Extend count');?>');
                return false;
            }
            $.ajax({
                type:"POST",
                url : BASE_URL+"/index.php/project/repostProject",
                data:"time="+time+"&day="+day+"&project_id="+<?php echo $projectDetail->id;?>,
                success:function(data){
                    var data = $.parseJSON(data);
                    if(data.status == "success"){
                        $("#days-extends").text(data.data);
                        $('#extend-alert').show();
                        $('#extend-alert').text(data.messages);
                        $('#extend-alert').addClass('green');
                    }else{
                        $('#extend-alert').show();
                        $('#extend-alert').text(data.messages);
                    }
                }
            });
        });
    </script>
<?php $this->load->view('footer'); ?>